import numpy as np
from scipy.stats import ttest_ind
import json 
import torch 

def get_metric(line):
    line = line.strip("\n")

    line = json.loads(line)
    dices = line["hds"]
    return dices

model_names = ["segresnet", "vnet", "swinunet2d", "transbts", 
                    "densehnet", "unet_plus", "att_unet3d", "att_unet25d", 
                    "att_unet2d", "att_unet3d_ml", "att_unet25d_ml", "att_unet2d_ml",
                    "unet3d", "unet25d", "unet2d", "unet3d_ml", "unet25d_ml", "unet2d_ml",
                    "nnunet", "fuse_unet"]

with open("./ibsr_res.txt") as f :
    lines = f.readlines()

    unet_dices = get_metric(lines[0])

    print(sum(unet_dices) / len(unet_dices))
    unet_ml_dices = get_metric(lines[15]) # unet ml
    print(sum(unet_ml_dices) / len(unet_ml_dices))

    fuse_unet = get_metric(lines[-1])
    # print(sum(fuse_unet) / len(fuse_unet))
    
res = ttest_ind(unet_dices, unet_ml_dices, alternative="less")

print(res)